package net.butfly.bus.config.bean;

import java.util.Map;

public class NodeBean {
	private String id;

	private ConnectionBean connection;

	private InvokerBean invoker;

	private String txMatching;

	private Map<String, Object> config;

	public NodeBean(String id, String txMatching, ConnectionBean typeBean, InvokerBean invoker, Map<String, Object> config) {
		this.id = id;
		this.txMatching = txMatching;
		this.connection = typeBean;
		this.invoker = invoker;
		this.config = config;
	}

	public String getId() {
		return id;
	}

	public Map<String, Object> getConfig() {
		return config;
	}

	public ConnectionBean getConnection() {
		return connection;
	}

	public InvokerBean getInvoker() {
		return invoker;
	}

	public void setTxMatching(String txMatching) {
		this.txMatching = txMatching != null ? txMatching.trim() : txMatching;
	}

	public boolean matchTx(String txCode) {
		if (txMatching != null) {
			if (txMatching.toUpperCase().equals(txCode.toUpperCase())) {
				return true;
			} else if (txMatching.toUpperCase().equals(txCode.toUpperCase()) || txMatching.equals("*")) {
				return true;
			} else if (txMatching.endsWith("*")) {
				if (txCode.toUpperCase().startsWith(txMatching.substring(0, txMatching.indexOf("*")).toUpperCase())) {
					return true;
				}
			}
		}
		return false;
	}

}
